$(document).ready(function(){

    var URL = "http://47.99.154.112:8011/";
    var getArticleInfoUrl = URL+"news/tools/news_ajax.ashx?action=GetArticleInfo&article_id="+ getUrlParameter("id");
    initEnvironmental();

    new Vue({
        el:"#mainVue",
        data:{
            title:"",   //标题
            time:0,     //日期
            mainContent:"",     //内容
            topIcon: "",   // 头部图标
            likeCount: ""  //阅读量
        },
        computed:{
            releaseTime:function(){
                console.log(typeof this.time);
                return typeof this.time == "string"?this.time.substring(0,10):"";
            }
        },
        created:function(){ //创建实例执行的函数，网络请求放在这里
            var _this = this;
            $.ajax(getArticleInfoUrl,{
                type:"GET",
                success:function(_data){

                    var jsonData = JSON.parse(_data);

                    if(jsonData.DataPacket.info.link_url!=null && jsonData.DataPacket.info.link_url.length>0) {
                        window.location.href = jsonData.DataPacket.info.link_url;
                        return;
                    }

                    _this.title = jsonData.DataPacket.info.title;
                    _this.time = jsonData.DataPacket.info.add_time;
                    _this.mainContent = jsonData.DataPacket.info.content;
                    _this.topIcon = URL+jsonData.DataPacket.info.img_url;
                    _this.likeCount = jsonData.DataPacket.info.like_count;

                    $("#topIcon").attr("content", _this.topIcon);
                    $("#topTitle").attr("content", _this.title);
                    $("title").text(_this.title);

                    $("#mainVue").css("display", "block");

                }
            })
        }

    });



    function initEnvironmental(){
        Date.prototype.Format = function (fmt) { //author: meizz
            var o = {
                "y+":this.getFullYear(),
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }
    }


//解析URL地址中携带的参数，并将参数的键值以键值对的形式存储在对象中，返回这个包含键值对的对象>>>>>>>>>>>>>>>>>>>>>>>>>>>
    function getUrlParameter(searchStr) {
        var urlParameterArray = {};
        $.each(location.search.replace("?", "").split("&"), function(i, e) {
            var parameterItemArray = e.split("=");
            urlParameterArray[parameterItemArray[0]] = parameterItemArray[1];
        });
        return urlParameterArray[searchStr];
    };
});
